﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Engine;
using Game.NetWork.Packages;
using Game.NetWork;
using SimpleJson;
using static System.Net.Mime.MediaTypeNames;
using Game.Server.Event;
using GameEntitySystem;
using static Game.BevelledShapeRenderer;
using static Game.TerrainContentsGenerator21;


namespace Game.Server.Plugins
{
    public class abc : AbstractProcessCmd
    {
        public override string Cmd => "abc";// 命令

        public override string Introduce => "abc"; // 描述

        public override int AuthLevel => 1000;// 权限等级

        public override DisplayType Display => DisplayType.All;// 显示类型

        public float timer = 0f;

        public float Interval = 10.0f; // 时间间隔

        public SubsystemAdjustableDelayGateBlockBehavior SubsystemAdjustableDelayGateBlockBehavior; // 依赖注入     

        public SubsystemTime subsystemtime;// 依赖注入

        public static string hdsa; // 静态变量

        public static bool IsEnabled { get; set; } = false; // 是否启用            

        public override void ProcessCmd()
        {
            hdsa = m_messageDatas[1]; // 静态变量赋值
            if (hdsa == "on")
            {
                DisplaySmallMessageNet广播( $"启用");
                IsEnabled = true; // 启用
            }
            if (hdsa == "off")
            {
                DisplaySmallMessageNet广播( $"禁用");
                IsEnabled = false; // 禁用
                
            }
        }

        public void DisplaySmallMessageNet广播(string text)  // 小消息方法 广播
        {
            var messagePackget = new MessagePackage("<c=red>系统广播</c>", text, 0, null);
            CommonLib.Net.QueuePackage(messagePackget);
        }

    }
    public class a1 : ServerPlugin , ICreatureSpawnEventHandle
    {
        public override int Version => 100;

        public ComponentPlayer componentPlayer;

        public a1(ComponentPlayer componentPlayer)
        {
            componentPlayer = GameManager.Project.Entities.FindComponent<ComponentPlayer>();
            this.componentPlayer = componentPlayer;
        }

        public override string Name => "a1";

        public static string 生物实体名 = "Ray"; // 生物实体名

        public byte FirstLevel => 1;

        public override void Initialize()
        {
            CreatureSpawnEventManager.AddObject(this);// 注册生物生成插件
        }

        public override void Load()
        {

        }

        public override void Save()
        {

        }
        public bool Update(SubsystemCreatureSpawn subsystemCreatureSpawn, float dt) // 生物生成插件  
        {
            try
            {
                // 每10秒触发  
                bool flag = subsystemCreatureSpawn.m_subsystemTime.PeriodicGameTimeEvent(10.0, 0.0); // 周期事件  
                if (flag)
                {
                    if (abc.IsEnabled) // 判断是否启用  
                    {
                        SubsystemTerrain subsystemTerrain = GameManager.Project.FindSubsystem<SubsystemTerrain>();
                        SubsystemSky m_subsystemSky = GameManager.Project.FindSubsystem<SubsystemSky>();
                        SubsystemTimeOfDay m_subsystemTimeOfDay = GameManager.Project.FindSubsystem<SubsystemTimeOfDay>();
                        SubsystemGameInfo m_subsystemGameInfo = GameManager.Project.FindSubsystem<SubsystemGameInfo>();
                        Point3 point3 = new Point3(0, 99, 0);
                        Vector3 vector3 = new Vector3(0f, 99f, 0f);
                        // 获取CreatureType对象  
                        
                        DisplaySmallMessageNet广播("生物生成插件生物生成");
                        try
                        {
                            Entity entity2 = DatabaseManager.CreateEntity(GameManager.Project, 生物实体名, true);
                            entity2.FindComponent<ComponentFrame>(true).Position = vector3;
                            entity2.FindComponent<ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                            entity2.FindComponent<ComponentSpawn>(true).SpawnDuration = 0f;
                            GameManager.Project.AddEntity(entity2);
                        }
                        catch (Exception e)
                        {
                            Log.Error(e.ToString());
                            DisplaySmallMessageNet广播("找不到");
                        }

                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
            return true;
        }

        public void DisplaySmallMessageNet广播(string text)  // 小消息方法 广播
        {
            var messagePackget = new MessagePackage("<c=red>系统广播</c>", text, 0, null);
            CommonLib.Net.QueuePackage(messagePackget);
        }

        public void OnEntityAdded(SubsystemCreatureSpawn subsystemCreatureSpawn, Entity entity)
        {
            
        }

        public void OnEntityRemoved(SubsystemCreatureSpawn subsystemCreatureSpawn, Entity entity)
        {
          
        }

        public void OnPlayerSpawned(PlayerData playerData, Entity playerEntity, Vector3 position)
        {
           
        }

        public void InitCreatureTypes(SubsystemCreatureSpawn subsystemCreatureSpawn, List<SubsystemCreatureSpawn.CreatureType> creatureTypes)
        {
            
        }
    }

}